import List.IList;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

public class Test {
    public static void main1(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        ArrayList<Integer> list2 = new ArrayList<>(list);
        list2.add(4);
        list2.add(5);
        list2.add(6);
        System.out.println(list2);
        List<Integer> L = list2.subList(1, 3);
        System.out.println(L);
        L.set(0, 99);
        System.out.println(L);
        System.out.println(list2);

        /*list2.remove(1);
        list2.remove(new Integer(99));
    }*/
    }

    public static void main(String[] args) {
            ArrayList<Integer> list = new ArrayList<>();
            list.add(1);
            list.add(2);
            list.add(3);
            ArrayList<Integer> list2 = new ArrayList<>(list);
            list2.add(4);
            list2.add(5);
            list2.add(6);
            System.out.println("===========for循环输出=============");
            for (int i = 0; i < list2.size(); i++) {
                System.out.print(list2.get(i)+"  ");
            }
        System.out.println();
         System.out.println("===========foreach循环输出=============");
        for (Integer  i:list2) {
            System.out.print(i+"  ");
        }
        System.out.println();
        System.out.println("===========iterator迭代器循环输出=============");
        Iterator<Integer> it=list2.iterator();
        while (it.hasNext()){
            System.out.print(it.next()+" ");
        }
        System.out.println();
        System.out.println("===========listIterator迭代器循环输出=============");
        ListIterator<Integer> it2= list2.listIterator();
        while (it2.hasNext()){
            System.out.print(it2.next()+" ");
        }
        System.out.println();
        System.out.println("===========listIterator迭代器倒序循环输出=============");
        ListIterator<Integer> it3= list2.listIterator();
        while (it2.hasPrevious()){
            System.out.print(it2.previous()+" ");
        }
        System.out.println();
        System.out.println("===========listIterator迭代器指定位置倒序循环输出=============");
        ListIterator<Integer> it4= list2.listIterator(3);
        while (it4.hasPrevious()){
            System.out.print(it4.previous()+" ");
        }
        System.out.println();
    }
}
